package com.dangdang.recursion;

public class ValidParen {
    public static void validParen(int n){
        generate(3,0,0,"");

    }

    public static void generate(int n,int left,int right,String s){
        if (left == n && right == n) {
            System.out.println(s);
        }

        if (left<n) {
            generate(n,left+1,right,s+"(");
        }

        if (right < left) {
            generate(n,left,right+1,s+")");
        }

    }


    public static void main(String[] args) {
        ValidParen.validParen(3);
    }
}
